package cn.tedu.learn.tea.infrastructure.data.converter;

import cn.tedu.learn.tea.domain.bo.ContentBO;
import cn.tedu.learn.tea.domain.bo.ContentDetailBO;
import cn.tedu.learn.tea.po.Content;
import cn.tedu.learn.tea.po.ContentDetail;
import cn.tedu.learn.tea.protocol.parm.ContentParam;
import cn.tedu.learn.tea.protocol.parm.ContentUpdateParam;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;

/**
 * 内容详情转换类
 */
@Component
public class ContentDetailConverter {

    /**
     * 内容param对象转内容po对象
     *
     * @param contentParam 内容param对象
     * @return 内容po对象
     */
    public ContentDetail paramToPo(ContentParam contentParam) {
        ContentDetail contentDetail = new ContentDetail();
        BeanUtils.copyProperties(contentParam, contentDetail);
        Long nowTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        contentDetail.setGmtModified(nowTime);
        return contentDetail;
    }

    /**
     * 内容修改param对象转内容po对象
     *
     * @param contentUpdateParam 内容修改param对象
     * @return 内容po对象
     */
    public ContentDetail paramToPo(ContentUpdateParam contentUpdateParam) {
        ContentDetail contentDetail = new ContentDetail();
        BeanUtils.copyProperties(contentUpdateParam, contentDetail);
        Long nowTime = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        contentDetail.setGmtModified(nowTime);
        return contentDetail;
    }

    /**
     * 内容详情po对象转内容详情bo对象
     *
     * @param contentDetail 内容po
     * @return 内容bo
     */
    public ContentDetailBO poToBo(ContentDetail contentDetail) {
        ContentDetailBO contentDetailBO = new ContentDetailBO();
        BeanUtils.copyProperties(contentDetail, contentDetailBO);
        return contentDetailBO;
    }
}
